/**
 * @param {number[]} tasks
 * @return {number}
 */
 var minimumRounds = function(tasks) {
  const mp = new Map()
  for(const x of tasks) {
    mp.set(x, ~~mp.get(x) + 1)
  }
  let ans = 0
  for(const [k, v] of mp) {
    let a = Math.floor(v/3)
    while(a !== 0 && (v - a*3) % 2 !== 0) a--
    if((v - a*3) % 2 !== 0) return -1
    ans += a + (v - a*3)/ 2
  }
  return ans
};